﻿using System.Collections.Generic;
using System.Linq;
using Pyramid.Bll;
using Pyramid.Models;

namespace Pyramid.Controllers
{
	public class PaymentBaseController : BaseController
	{
		protected List<PayeeRecord> PrepareForPaymentListView(PaymentQueryModel model, bool includeAll = false)
		{
			var payeeRecords = PaymentHelper.NewInstance.Query(model, User, includeAll);
			var currentPage = (model.PageNum ?? 1) - 1;
			var pageSize = model.NumPerPage ?? 20;
			var vm = new PagerModel
			{
				PageSize = pageSize,
				CurrentPageIndex = currentPage,
				TotalCount = payeeRecords.Count()
			};
			ViewBag.Bag = vm;
			ViewBag.QueryModel = model;
			return payeeRecords.OrderByDescending(x => x.Id).Skip(currentPage*pageSize).Take(pageSize).ToList();
		}
	}
}